<form action="/admini/express/price/"  method="get" style="margin-top:10px" id="form1">
    <input type="hidden" id="epId" name="epId" value="<?php echo $this->epId==""?"":$this->epId;?>" />
    <input type="hidden" id="cityId" name="cityId" value="<?php echo $this->cityId==""?"":$this->cityId;?>" />
    <input type="hidden" id="isDisable" name="isDisable" value="<?php echo $this->isDisable==""?"":$this->isDisable;?>" />
</form>
<div class="">
    <div class="admin_nrtop">
        <div class="pricetop">
            <div class="priguolv">
                <div class="addressbookguojia">
                    <div class="addressbookinput">
                        <input type="text" data="empty" value="<?php if($this->cityId != ""){ $cityItem = Application_Model_city::load($this->cityId);echo $cityItem->name;}?>" name="name" placeholder="按国家筛选" class="txtBxF">
                        <i></i>
                    </div>
                    <div style="display:none;" class="share_guojiaceng">
                                <div class="share_remen">
                                    <h2>热门国家和地区</h2>
                                    <ul class="share_countrylist">
                                        <li>
                                            <a cid="1">美国</a>
                                        </li>
                                        <li>
                                            <a cid="2">加拿大</a>
                                        </li>
                                        <li>
                                            <a cid="3">澳大利亚</a>
                                        </li>
                                        <li>
                                            <a cid="47">日本</a>
                                        </li>
                                        <li>
                                            <a cid="39">台湾</a>
                                        </li>
                                        <li>
                                            <a cid="4">新西兰</a>
                                        </li>
                                        <li>
                                            <a cid="5">英国</a>
                                        </li>
                                        <li>
                                            <a cid="42">马来西亚</a>
                                        </li>
                                    </ul>
                                </div>
                                <div class="share_allcountry">
                                    <h2>全部国家和地区</h2>
                                    <ul class="share_countryzm">
                                        <?php foreach ($this->words as $char) { ?>
                                            <li <?= $char == 'A' ? 'class="share_zmon"' : '' ?>><a href="javascript:;"><?= $char ?></a></li>
                                        <?php } ?>
                                    </ul>
                                    <div class="country_content">
                                    <?php foreach ($this->words as $char) { ?>
                                        <ul class="share_countrylist <?= $char != 'A' ? '' : 'on' ?>" >
                                            <?php
                                                $citys = Application_Model_city::GetBySortCode($char);
                                                foreach ($citys as $city) { ?>
                                                <li><a href="javascript:;" cid="<?= $city->Id ?>"><?= $city->Name ?></a></li>
                                        <?php } ?>
                                        </ul>
                                    <?php } ?>
                                    </div>
                                </div>
                            </div>
                </div>
            </div>
            <div class="priguolv2">
                <select name="selectepId">
                    <option value="" selected="selected">全部</option>
                    <?php if($this->expresscomp){ foreach ($this->expresscomp as $eccomp) { ?>
                        <option value="<?php echo $eccomp->id; ?>" <?php echo $this->epId == $eccomp->id ? ' selected="selected" ' : '' ?> ><?php echo $eccomp->name; ?></option>
                    <?php }} ?>
                </select>
            </div>
            <div class="priguolv3"><a href="/admini/express/price/">取消筛选</a></div>
            
        </div>
    </div>
    
    <div class="couriercommpany">
        <table>
            <tbody>
            <?php  if($this->priceList){ ?>
                <tr>
                    <th class="pr1"></th>
                    <th class="pr2">快递logo</th>
                    <th class="pr3">快递名称</th>
                    <th class="pr4">国家</th>
                    <th class="pr5">首重(kg)</th>
                    <th class="pr6">首重价(元)</th>
                    <th class="pr7">最大限重(kg)</th>
                    <th class="pr8">最大限长(cm)</th>
                    <th class="pr9">状态</th>
                    <th class="pr10">操作</th>
                </tr>
            <?php
                foreach ($this->priceList as $Item) { 
            ?> 
            <tr>
                    <td class="pr1"><input type="checkbox" value="<?php echo $Item->id;?>" name="checkbox"></td>
                    <td class="pr2">
                        <div class="cclogo">
                            <?php if ($Item->Express->Logo){ ?>
                            <img src="<?php echo $Item->Express->Logo; ?>" width="120px" height="60px">
                            <?php }else{
                                echo '无图';
                            }?>
                        </div>
                    </td>
                    <td class="pr3"><div class="ccname"><h2><a href="/admini/express/prdetail/id/<?php echo $Item->Id;?>"><?php echo $Item->Express->Name;?></a></h2></div></td>
                    <td class="pr4"><?php echo $Item->City->Name;?></td>
                    <td class="pr5"><?php echo $Item->FirstWeight;?></td>
                    <td class="pr6"><?php echo $Item->FirstPrice;?></td>
                    <td class="pr7"><?php echo $Item->Maxkg;?></td>
                    <td class="pr8"><?php echo $Item->Maxcm;?></td>
                    <td class="pr9">
                        <?php if($Item->IsDisable == 1){?>
                            <span class="prch">关闭中</span>
                        <?php } else { ?>
                            <span class="prlv">已启用</span>
                        <?php } ?>
                    </td>
                    <td class="pr10">
                        <p class="ccnav">
                            <a href="/admini/express/addprice/epId/<?php echo $Item->ExpressId;?>/cityId/<?php echo $Item->CityId;?>">编辑</a>
                            <span>|</span>
                            <?php if($Item->IsDisable == 1){?>
                                <a href="javascript:void(0)" name="<?php echo $Item->id;?>" class="EnableOrDisable" i="开启">开启</a>
                            <?php } else { ?>
                                <a href="javascript:void(0)" name="<?php echo $Item->id;?>" class="EnableOrDisable" i="关闭">关闭</a>
                            <?php } ?>
                        </p>
                    </td>
                </tr>
            <?php } }  if(!$this->priceList){
                echo "<font size='4' color='red'>暂无数据</font>";
                }?>  
            </tbody>
        </table>
        
        <div class="pircepl">
            <p><a href="javascript:;" id="selAll" >全选</a><i>-</i><a href="javascript:;" id="batchEnable">批量启用</a><a href="javascript:;" id="batchDisable">批量关闭</a></p>
        </div>
    </div>
    <div class="ccbar">
        <div class="pirbar">
            <ul>
                <li><a href="/admini/express/addprice" class="ccbotton"><span>添加报价</span></a></li>
                <li><a href="/admini/express/batchup" class="ccbotton2"><span>批量导入报价表</span></a></li>
            </ul>
        </div>
        <?php
            echo $this->partial('paging.phtml', array("pages" => $this->priceAll,"pamas"=>"epId=$this->epId&isDisable=$this->isDisable&cityId=$this->cityId"));        
        ?>
    </div>
</div>
<script>
    $(function(){
        //显示国家
        $('.addressbookinput').hover(function() {
        }, function() {
            // $('.share_guojiaceng').hide();
        }).click(function() {
            $('.share_guojiaceng').toggle();
        });

        //选择国家
        $('.share_countrylist a').bind('click', function() {
            var city  = $(this).text();
            var state = $(this).attr("cid");
            $("#cityId").val(state);
            $("#cityName").val(city);
            $('.share_guojiaceng').hide();

            $("#form1 #cityId").val(state);
            $('#form1').submit();
            return false;
        });

        //切换国家
        $('.share_countryzm a').each(function(index, item) {
            $(item).click(function() {
                $('.share_countryzm li.share_zmon').removeClass('share_zmon');
                $(this).parent().addClass('share_zmon');
                $('.country_content ul').hide();
                $('.country_content ul').eq(index).show();
                return false;
            });
        });

        //隐藏div
        $('.share_guojiaceng').mouseout(function(e){
            if(isMouseLeaveOrEnter(e, this)){
                $(this).hide();
            }
        })

        //启用禁用
        $(".EnableOrDisable").click(function(){
            var id = $(this).attr('name');
            var i = $(this).attr("i");
            if(confirm("您确定"+i+"该快递的国家？","提示信息")){
                $.ajax({    
                    type: 'POST',
                    url: '/admini/express/eodprice/id/'+id,
                    success: function(data) {
                        if(data == 1){
                            alert(i+"成功！");
                            location.reload();
                        }else{
                            alert("发生未知错误，请重新操作");
                        }
                    }
                });
            }
        });

        //快递类型选择
        $('[name=selectepId]').change(function(){
            var epId = $('[name=selectepId]').val();
            setNameVal('epId', epId);
        })

        //全选
        $('#selAll').click(function(){
            $('[name=checkbox]').attr('checked', 'checked');
        })

        //批量启用
        $("#batchEnable").click(function(){
            var idlist = checkAll();
            if(idlist == ""){
                alert("请选择您需要操作的记录！");
                return false;
            }
            if(confirm("您确定批量启用该快递的国家？","提示信息")){
                $.ajax({    
                    type: 'POST',
                    url: '/admini/express/enableprice/idlist/'+idlist,
                    success: function(data) {
                        if(data == 1){
                            alert("批量启用成功！");
                            location.reload();
                        }else{
                            alert("发生未知错误，请重新操作");
                        }
                    }
                });
            }
        });

        //批量禁用
        $("#batchDisable").click(function(){
           var idlist = checkAll();
           if(idlist == ""){
                alert("请选择您需要操作的记录！");
                return false;
            }
           if(confirm("您确定批量禁止该快递的国家？","提示信息")){
                $.ajax({    
                    type: 'POST',
                    url: '/admini/express/disableprice/idlist/'+idlist,
                    success: function(data) {
                        if(data == 1){
                            alert("批量禁止成功！");
                            location.reload();
                        }else{
                            alert("发生未知错误，请重新操作");
                        }
                    }
                });
            }
        });

    })

    function checkAll(){
        var idlist = '';
        $('input[name="checkbox"]:checked').each(function(){
            idlist+= $(this).val()+',';
        });
        return idlist;
    }

    function setNameVal(Name,val)
    {
        $("#form1 #"+Name).val(val);
        $("#form1").submit();
    }

    //阻止冒泡
    function isMouseLeaveOrEnter(e, handler) 
    {
        if (e.type != 'mouseout' && e.type != 'mouseover') return false;
        var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement;
        while (reltg && reltg != handler)
            reltg = reltg.parentNode;
        return (reltg != handler);
    }
</script>